package satir.card.factory;

import org.json.JSONArray;
import org.json.JSONObject;

import satir.card.Deck;
import satir.framework.refectoring.Factory;

/**
 * A factory for creating Deck objects.
 * @version 3.0 April 2012
 * @author Creative Family
 */
public class MagicToolDeckFactory implements Factory {

    /**
     * Creates the.
     * @param json
     *            the JSON object
     * @return the object
     * @see Factory, LazyInitiator
     */
    @Override
    public Object create(final JSONObject json) {
	Deck concreteProduct = new Deck();
	try {
	    JSONArray atCardKeysJSArr = json.getJSONArray("atcardKeys");
	    String[] cardKeys = new String[atCardKeysJSArr.length()];
	    for (int i = 0; i < atCardKeysJSArr.length(); i++) {
		cardKeys[i] = atCardKeysJSArr.getString(i);
	    }
	    concreteProduct.loadCard("AccomplishToolCard", cardKeys);
	    JSONArray skipCardKeysJSArr = json.getJSONArray("skipcardKeys");
	    cardKeys = new String[skipCardKeysJSArr.length()];
	    for (int i = 0; i < skipCardKeysJSArr.length(); i++) {
		cardKeys[i] = skipCardKeysJSArr.getString(i);
	    }
	    concreteProduct.loadCard("SkipToolCard", cardKeys);
	} catch (Exception e) {
	    e.printStackTrace();
	}

	return concreteProduct;
    }
}
